package com.wanaofu.model;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.ForeignKey;

@Entity
@Table(name = "wh_batch_item")
public class WarehouseBatchItem extends AbstractBaseEntity implements Serializable {
	private static final long serialVersionUID = -5820332764265899408L;
	
	public WarehouseBatchItem() {
	}
	
	public WarehouseBatchItem(ProductInfo product,Integer amt,Warehouse pos) {
		this.amount = amt ;
		this.product = product ;
		this.position = pos;
	}
	public WarehouseBatchItem(ProductInfo product,Integer amt,Warehouse pos,AbstractWarehouseBatch batch) {
		this(product, amt, pos) ;
		this.batch = batch;
	}	
	
	@Column(name = "amount", nullable=false)
	@Min(1)
	@Max(2000)
	@NotNull
	private Integer amount = 1 ;
	
	@ManyToOne(cascade = CascadeType.ALL)
	@ForeignKey(name="FK_PRODUCT_INFO_ID")
	@JoinColumn(name="product_id")
	@NotNull
	@Valid
	private ProductInfo product;

	@ManyToOne(cascade = CascadeType.ALL)
	@ForeignKey(name="FK_WAREHOUSE_ID")
	@JoinColumn(name="warehouse_id")
	@NotNull	
	@Valid
	private Warehouse position ;
	
	@ManyToOne(cascade = CascadeType.ALL)
	@ForeignKey(name="FK_WH_BATCH")
	@JoinColumn(name="batch_id")
	@NotNull
//	@Valid	
	private AbstractWarehouseBatch batch ;

	@Override
	boolean businessEquals(Object p) {
		return true;
	}
	
	/*  ========================= get/set Methods ================================  */
	public Integer getAmount() {
		return amount;
	}
	public void setAmount(Integer amount) {
		this.amount = Math.abs(amount);
	}
	public ProductInfo getProduct() {
		return product;
	}
	public void setProduct(ProductInfo product) {
		this.product = product;
	}
	public Warehouse getPosition() {
		return position;
	}
	public void setPosition(Warehouse position) {
		this.position = position;
	}
	public AbstractWarehouseBatch getBatch() {
		return batch;
	}
	public void setBatch(AbstractWarehouseBatch batch) {
		this.batch = batch;
	}

}
